package com.ruoyi.project.jiaqin.answer.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.jiaqin.answer.domain.JiaqinAnswer;
import com.ruoyi.project.jiaqin.answer.service.IJiaqinAnswerService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 回答Controller
 * 
 * @author admin
 * @date 2020-12-30
 */
@Controller
@RequestMapping("/jiaqin/answer")
public class JiaqinAnswerController extends BaseController
{
    private String prefix = "jiaqin/answer";

    @Autowired
    private IJiaqinAnswerService jiaqinAnswerService;

    @RequiresPermissions("jiaqin:answer:view")
    @GetMapping()
    public String answer()
    {
        return prefix + "/answer";
    }

    /**
     * 查询回答列表
     */
    @RequiresPermissions("jiaqin:answer:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiaqinAnswer jiaqinAnswer)
    {
        startPage();
        List<JiaqinAnswer> list = jiaqinAnswerService.selectJiaqinAnswerList(jiaqinAnswer);
        return getDataTable(list);
    }

    /**
     * 导出回答列表
     */
    @RequiresPermissions("jiaqin:answer:export")
    @Log(title = "回答", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiaqinAnswer jiaqinAnswer)
    {
        List<JiaqinAnswer> list = jiaqinAnswerService.selectJiaqinAnswerList(jiaqinAnswer);
        ExcelUtil<JiaqinAnswer> util = new ExcelUtil<JiaqinAnswer>(JiaqinAnswer.class);
        return util.exportExcel(list, "answer");
    }

    /**
     * 新增回答
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存回答
     */
    @RequiresPermissions("jiaqin:answer:add")
    @Log(title = "回答", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiaqinAnswer jiaqinAnswer)
    {
        return toAjax(jiaqinAnswerService.insertJiaqinAnswer(jiaqinAnswer));
    }

    /**
     * 修改回答
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        JiaqinAnswer jiaqinAnswer = jiaqinAnswerService.selectJiaqinAnswerById(id);
        mmap.put("jiaqinAnswer", jiaqinAnswer);
        return prefix + "/edit";
    }

    /**
     * 修改保存回答
     */
    @RequiresPermissions("jiaqin:answer:edit")
    @Log(title = "回答", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiaqinAnswer jiaqinAnswer)
    {
        return toAjax(jiaqinAnswerService.updateJiaqinAnswer(jiaqinAnswer));
    }

    /**
     * 删除回答
     */
    @RequiresPermissions("jiaqin:answer:remove")
    @Log(title = "回答", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiaqinAnswerService.deleteJiaqinAnswerByIds(ids));
    }
}
